<template>
  <div
    class="cross-pass"
    v-loading="loading"
    element-loading-text="正在加载数据..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="left-box" v-if="!loading">
      <div class="playground-container">
        <div class="playground-top">
          <div class="success-detail">
            <img src="../../assets/image/pass/solid.png" alt="" />
            <span>成功传中</span>
          </div>
          <div class="fail-detail">
            <img
              src="../../assets/image/pass/square.png"
              class="square"
              alt=""
            />
            <span>失败传中</span>
          </div>
        </div>
        <HalfPlayGround
          :successful_cross="cross.Successful"
          :failed_cross="cross.Unsuccessful"
        />
        <img
          class="attack-arrow"
          src="../../assets/image/playerGround/rightArrow.png"
          alt=""
        />
        <div class="cross-zone">
          <CrossesZone :table="cross.Table"></CrossesZone>
        </div>
      </div>
    </div>
    <div class="right-box" v-if="!loading">
      <div class="ant-v">
        <div class="two-graph">
          <div class="one-graph">
            <div class="one-graph-title">传中总数/成功率</div>
            <CrossScatter
              :cross-pass="cross.Cross"
              :player-name="cross.playerName"
            />
          </div>
          <div class="one-graph">
            <div class="one-graph-title">传中成功/90</div>
            <CrossesSuccessful :cross-success="cross['crossSuccess/90']" />
          </div>
        </div>
        <div class="graph-legend">
          {{ cross.playerName }}在中超的传球数据与其他球员的对比
        </div>
      </div>
      <CrossesReceiver :table="cross.Receiver"></CrossesReceiver>
    </div>
  </div>
</template>

<script>
import HalfPlayGround from "../playground/HalfPlayGround";
import CrossScatter from "../ant_v/crossPass/CrossScatter";
import CrossesZone from "../tableData/CrossesZone";
import CrossesSuccessful from "../ant_v/crossPass/CrossesSuccessful";
import CrossesReceiver from "../tableData/CrossesReceiver";
import axios from "axios";
export default {
  name: "Crosses",
  data() {
    return {
      loading: true,
      cross: "",
    };
  },
  components: {
    HalfPlayGround,
    CrossesZone,
    CrossesSuccessful,
    CrossesReceiver,
    CrossScatter,
  },
  watch: {
    $route: {
      handler(to, from) {
        console.log("from:", from);
        console.log("to:", to);
        const { playerId } = to.params;
        // console.log("toId:", playerId);
        if (playerId) {
          this.getCrosses(playerId);
        }
      },
      immediate: true,
    },
  },
  async created() {
    // const playerId = this.$store.state.currPlayerId;
    // this.getCrosses(playerId);
  },
  methods: {
    async getCrosses(playerId) {
      const { data } = await axios.get(
        `http://8.141.159.127:3000/api/v1/players/actions/crossupdate/${playerId}`
      );
      this.cross = data;
      this.loading = false;
    },
  },
};
</script>

<style scoped lang="scss">
.cross-pass {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: space-between;
}
.left-box {
  height: 456px;
  margin-left: 90px;
}
.right-box {
  width: 560px;
  height: 413px;
  margin-top: 18px;
  margin-right: 70px;
  /*background-color: yellow;*/
}
.playground-container {
  position: relative;
  width: 620px;
  height: 456px;
  /*background-color: red;*/
  margin-top: 18px;
  .playground-top {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 591px;
    color: #656f73;
    line-height: 25px;
    font-size: 16px;
    height: 25px;
    text-align: left;
    /*background-color: #656F73;*/
    div {
      width: 100px;
      height: 25px;
      /*background-color: yellow;*/
      display: flex;
      justify-content: space-between;
      align-items: center;
      img {
        /*background-color: orange;*/
        width: 35px;
        height: 25px;
      }
      .square {
        width: 15px;
        height: 15px;
      }
    }
    .fail-detail {
      margin-left: 20px;
      span {
        margin-right: 15px;
      }
    }
  }
  .playground-right {
    position: absolute;
    top: 30px;
    left: 591px;
    color: #bd1e1e;
    width: 32px;
    height: 323px;
    /*background-color: blue;*/
  }
  .attack-arrow {
    position: absolute;
    top: 267px;
    left: 541px;
    width: 150px;
    height: 40px;
    /*background-color: blue;*/
    transform: rotate(-90deg);
    -ms-transform: rotate(-90deg); /* IE 9 */
    -moz-transform: rotate(-90deg); /* Firefox */
    -webkit-transform: rotate(-90deg); /* Safari 和 Chrome */
    -o-transform: rotate(-90deg); /* Opera */
  }
  .cross-zone {
    width: 591px;
    height: 90px;
    margin-top: 13px;
    background-color: #b500fe;
  }
}
.ant-v {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /*background-color: red;*/
  line-height: 10px;
  width: 100%;
  height: 223px;
  .two-graph {
    display: flex;
    justify-content: space-between;
    .one-graph {
      width: 230px;
      height: 200px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .one-graph-title {
        height: 20px;
        line-height: 20px;
      }
    }
  }
  .graph-legend {
    height: 25px;
    color: #656f73;
    font-size: 14px;
    line-height: 25px;
  }
}
</style>
